package com.tf.integrated.controller;

import com.ccssoft.m8.common.web.BaseController;
import com.tf.integrated.config.Config;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestTemplate;
import java.util.Map;
/**
 * 智能管理接口
 * @author allen
 * @date: 2020年9月14日上午10:56:20
 */
@Api(value = "智能管理接口",description="IntelligentMgrController")
@RestController
@RequestMapping("/intelligent")
public class IntelligentMgrController extends BaseController
{
    @ApiOperation("获取智能分析算法参数")
    @GetMapping("/analyseParams")
    @CrossOrigin(origins = "*",maxAge = 86400)
    public String analyseParams(@RequestParam Map<String, Object> data)
    {
        if(data!=null&&data.size()>0)
        {
            String host = (String)data.get("host");
            int chn =   Integer.valueOf((String)data.get("chn"));
            HttpMethod method = HttpMethod.GET;
            HttpHeaders headers = new HttpHeaders();
            headers.set("X-Token", Config.getmCurtoken(host));
            String analyseResults = Config.client(Config.getStarturlpre(host)+"/intelligent/analyseParams?chn="+chn,method,null,headers);
            logger.error("info on  intelligent/analyseParams analyseResults===" + analyseResults);
            LogController.add("/intelligent/analyseParams",LogController.METHOD_GET,1);
            return analyseResults;
        }
        LogController.add("/intelligent/analyseParams",LogController.METHOD_GET,0);
        return "{}";
    }

    @ApiOperation("设置智能分析算法参数")
    @PutMapping("/analyseParams")
    @CrossOrigin(origins = "*",maxAge = 86400)
    public String setanalyseParams(@RequestParam Map<String, Object> data,@RequestBody String param)
    {
        if(data!=null&&data.size()>0&&param!=null&&param.equals("")==false)
        {
            String host = (String)data.get("host");
            int chn = Integer.valueOf((String)data.get("chn"));
            HttpMethod method = HttpMethod.PUT;
            HttpHeaders headers = new HttpHeaders();
            headers.set("X-Token", Config.getmCurtoken(host));
            String analyseResults = Config.client(Config.getStarturlpre(host)+"/intelligent/analyseParams?chn="+chn,method,param,headers);
            logger.error("info on  intelligent/setanalyseParams analyseResults===" + analyseResults);
            LogController.add("/intelligent/analyseParams",LogController.METHOD_PUT,1);
            return analyseResults;
        }
        LogController.add("/intelligent/analyseParams",LogController.METHOD_PUT,0);
        return "{}";
    }

    @ApiOperation("获取智能分析能力集")
    @GetMapping("/caps")
    @CrossOrigin(origins = "*",maxAge = 86400)
    public String caps(@RequestParam Map<String, Object> data)
    {
        if(data!=null&&data.size()>0)
        {
            String host = (String)data.get("host");
            HttpMethod method = HttpMethod.GET;
            HttpHeaders headers = new HttpHeaders();
            headers.set("X-Token", Config.getmCurtoken(host));
            String analyseResults = Config.client(Config.getStarturlpre(host) + "/intelligent/caps", method, null, headers);
            logger.error("info on  intelligent/caps analyseResults===" + analyseResults);
            LogController.add("/intelligent/caps", LogController.METHOD_GET, 1);
            return analyseResults;
        }
        LogController.add("/intelligent/caps", LogController.METHOD_GET, 0);
        return "{}";
    }

    @ApiOperation("获取智能分析预案")
    @GetMapping("/schemes")
    @CrossOrigin(origins = "*",maxAge = 86400)
    public String schemes(@RequestParam Map<String, Object> data)
    {
        if(data!=null&&data.size()>0)
        {
            String host = (String)data.get("host");
            int chn = Integer.valueOf((String)data.get("chn"));
            HttpMethod method = HttpMethod.GET;
            HttpHeaders headers = new HttpHeaders();
            headers.set("X-Token", Config.getmCurtoken(host));
            String analyseResults = Config.client(Config.getStarturlpre(host)+"/intelligent/schemes?chn="+chn,method,null,headers);
            logger.error("info on  intelligent/schemes analyseResults===" + analyseResults);
            LogController.add("/intelligent/schemes",LogController.METHOD_GET,1);
            return analyseResults;
        }
        LogController.add("/intelligent/schemes",LogController.METHOD_GET,0);
        return "{}";
    }

    @ApiOperation("设置智能分析预案")
    @PutMapping("/schemes")
    @CrossOrigin(origins = "*",maxAge = 86400)
    public String setschemes(@RequestParam Map<String, Object> data,@RequestBody String param)
    {
        if(data!=null&&data.size()>0&&param!=null&&param.equals("")==false)
        {
            String host = (String)data.get("host");
            int chn = Integer.valueOf((String)data.get("chn"));
            HttpMethod method = HttpMethod.PUT;
            HttpHeaders headers = new HttpHeaders();
            headers.set("X-Token", Config.getmCurtoken(host));
            String analyseResults = Config.client(Config.getStarturlpre(host)+"/intelligent/schemes?chn="+chn,method,param,headers);
            logger.error("info on  intelligent/setschemes analyseResults===" + analyseResults);
            LogController.add("/intelligent/schemes",LogController.METHOD_PUT,1);
            return analyseResults;
        }
        LogController.add("/intelligent/schemes",LogController.METHOD_PUT,0);
        return "{}";
    }
}